﻿@using Masa.Auth.Web.Admin.Rcl.Pages.Subjects.Users.Model
@inherits AdminCompontentBase

<DefaultSheetDialog Value="Visible" ValueChanged=UpdateVisible Title="@T("Edit Role")">
    <MForm Model="Role" EnableValidation EnableI18n>
        <AutoHeight Overflow AutoClass="mt-6">
            <HeaderContent>
                <div class="d-flex">
                    <div class="mx-auto m-btn-group">
                        <ButtonGroup @bind-Value="Tab" TValue="UpdateRoleTabs" />
                    </div>
                </div>
            </HeaderContent>
            <AutoHeightContent>
                <MWindow Value="Tab.ToString()" Class="pb-1">
                    <MWindowItem Value="UpdateRoleTabs.BasicInformation.ToString()">
                        <DefaultTitle Class="mb-4">@T("BasicInformation")</DefaultTitle>
                        <STextField TValue="string" Value="Role.Name" ValueChanged="NameChanged" Class="mb-6" Label="@T("Name")" />
                        <STextField @bind-Value="Role.Code" Class="mb-6" Label="@T("Code")" />
                        <STextField @bind-Value="Role.Limit" TValue="int" OnChange=LimitChanged Class="mb-6" Label="@T("Limit the number of bindings")" />
                        <RoleSelect Value="RoleDetail.ParentRoles" Class="mb-6" Readonly Label="@T("Superior Role")" />
                        <RoleOwner RoleId=RoleId Class="mb-6" />
                        <STextarea @bind-Value="Role.Description" Outlined Class="mb-6" Label="@T("Description")" />
                        <Record Creator="@RoleDetail.Creator" CreationTime="@RoleDetail.CreationTime" Modifier="@RoleDetail.Modifier" ModificationTime="@RoleDetail.ModificationTime" />                      
                    </MWindowItem>
                    <MWindowItem Value="UpdateRoleTabs.Permission.ToString()">
                        <RoleSelectForRole RoleId=RoleId @bind-Value="Role.ChildrenRoles" Class="mb-6 mt-2" />
                        <div class="global-nav" style="display: flex;max-height:calc(100vh - 230px);">
                            <PermissionsConfigure @ref="_permissionsConfigureRef"
                                Roles=Role.ChildrenRoles 
                                HasPreview
                                @bind-Value=Role.Permissions
                                @bind-Preview=@Preview/>
                        </div>
                    </MWindowItem>
                </MWindow>
            </AutoHeightContent>
            <FooterContent>
                <div class="d-flex mt-6" style="height:40px;">
                    <EnableSwitch @bind-Value="Role.Enabled" />
                    <MSpacer></MSpacer>
                    @if(Tab == UpdateRoleTabs.Permission)
                    {
                        <SButton Medium Outlined Class="mr-6" OnClick="@(() => Preview = true)">@T("Preview")</SButton>
                    }
                    <SButton Medium OnClick="@(() => UpdateRoleAsync(context!))">@T("Save")</SButton>
                </div>
            </FooterContent>
        </AutoHeight>
    </MForm>
</DefaultSheetDialog>